package com.itheima.execption;

import com.itheima.pojo.Result;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.sql.SQLException;

@RestControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(Exception.class)
    public Result ex1(Exception e){
        e.printStackTrace();

        return Result.error("对不起，操作失败，请联系管理员");

    }

    @ExceptionHandler(SQLException.class)
    public Result ex2(SQLException e){
        e.printStackTrace();

        return Result.error("请勿重复添加");
    }
}
